﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Text;
using System.Data;
using System.Collections;

public partial class YSFGL_YSFGLCX : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!Page.IsPostBack)
    {
      if (!ProjectPrivate.GetQX("23"))
      {
        Server.Transfer("~\\blank.aspx");
      }
      date1.Date = CommonUse.GetYC();
      date2.Date = CommonUse.GetYM();
    }
    BindGrid();
  }

  protected void BindGrid()
  {
    StringBuilder sbSql = new StringBuilder();
    sbSql.Append(@"select  ROW_NUMBER() OVER (ORDER BY a.cbsjid desc) AS xh,a.*,convert(varchar,a.CBSJ,23) BYCBSJ,
c.KHMC,c.KH,c.IC,c.XXDZ,c.KHXX_SFSB,D.YQXZ,e.XM,b.BQQL,b.yqxzid,b.bqql_sfsb,
B.JG,B.JJ,b.YSJG SR,B.YSJJ JGJJ,B.YSFY BQFY,b.ssql,b.SHRXM,convert(varchar,b.SHSJ,23) SHSJ
FROM      sjlr_cbsj A join
(select a.*,b.xm SHRXM from sjlr_bqql a left join sys_user b on a.shr=b.dlm) B on a.cbsjid=b.cbsjid 
            left join jcxx_khxx c on a.khid=c.khid 
            left join jcxx_yqxz d on D.yqxzid=b.yqxzid  
            left join sys_user e on e.dlm=a.dlm
    WHERE ");
    if (ddlZT.SelectedValue == "0")
    {
      sbSql.Append("a.cbsj>=@0 and a.cbsj<=cast(@1 as datetime) and bqql_sfsb=1 ");
    }
    if (ddlZT.SelectedValue == "1")
    {
      sbSql.Append("b.shsj>=@0 and b.shsj<=cast(@1 as datetime) and bqql_sfsb=2 ");
    }
    //sbSql.Append("order by a.cbsjid desc");
    SqlParameter[] cmdParams = { new SqlParameter("@0", SqlDbType.VarChar, 10), new SqlParameter("@1", SqlDbType.VarChar, 10) ,
                               new SqlParameter("@2", SqlDbType.VarChar, 10)};
    cmdParams[0].Value = date1.Text;
    cmdParams[1].Value = date2.Text;
    cmdParams[2].Value = SysManage.Get_User;
    DataSet ds = DbHelperSQL.Query(sbSql.ToString(), cmdParams);
    ASPxGridView1.DataSource = ds;
    ASPxGridView1.DataBind();
  }

  protected void btnQuery_Click(object sender, EventArgs e)
  {

  }

  protected void btnExport_Click(object sender, EventArgs e)
  {
    this.ASPxGridViewExporter1.WriteXlsToResponse();
  }

  protected void cpPopup_Callback(object source, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
  {
    litText.Text = CBSJ.GetNotes(e.Parameter).ToString();
  }
}
